﻿using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPRedisHelper
{
    public class RedisManager
    {
        public static string _conn = ConfigurationManager.AppSettings["RedisHost"] ?? "127.0.0.1:6379";
        private static ConnectionMultiplexer _redis;
        private static object _lock = new object();
        public static ConnectionMultiplexer Manager
        {
            get
            {
                if(_redis==null)
                {
                    lock(_lock)
                    {
                        if (_redis != null) return _redis;
                        _redis = GetManager();
                        return _redis;

                    }
                }
                return _redis;

            }
        }

        private static ConnectionMultiplexer GetManager(string connectionString = null)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                connectionString = _conn;
            }

            return ConnectionMultiplexer.Connect(connectionString);
        }



    }
}
